<%@ page import="java.net.URLDecoder" %>
<%@ page import="pojo.Student" %>
<%@ page import="java.util.List" %><%--
  Created by IntelliJ IDEA.
  User: HP
  Date: 2021/10/27
  Time: 15:45
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>学生信息管理</title>
</head>
<body>
<%
    Cookie[] cookies = request.getCookies();
    String[] s = null;

    if (cookies != null) {
        for (Cookie cookie : cookies) {
            if (URLDecoder.decode(cookie.getName(), "utf-8").equals("nameinfo")) {
                String str = URLDecoder.decode(cookie.getValue(), "utf-8");
                s = str.split("-");
            }
        }
    }
%>
欢迎<%=s[0]%>
<h3 align="center">学生列表</h3>
<hr/>
<table width="800" border="1" align="center">
    <tr>
        <th>学号</th>
        <th>姓名</th>
        <th>密码</th>
        <th>性别</th>
        <th>专业</th>
        <th>年龄</th>
        <th colspan="2">操作</th>
    </tr>
    <%
        Student student = new Student();
        List<Student> stuList = student.findAllStudents();
        for (Student stu : stuList) {
    %>
    <%if (s[0].equals(stu.getName())) {%>
    <tr>
        <td bgcolor="aqua"><%=stu.getId() %>
        </td>
        <td bgcolor="aqua"><%=stu.getName() %>
        </td>
        <td bgcolor="aqua"><%=stu.getPassword() %>
        </td>
        <td bgcolor="aqua"><%=stu.getSex() %>
        </td>
        <td bgcolor="aqua"><%=stu.getMajor() %>
        </td>
        <td bgcolor="aqua"><%=stu.getAge() %>
        </td>
        <td>
            <a href="/updatestu.jsp?id=<%=stu.getId()%>&name=<%=stu.getName()%>&age=<%=stu.getAge()%>">修改</a>
            <a href="DelateStudentServlet?id=<%=stu.getId()%>">删除</a>
        </td>
    </tr>
    <%} else {%>
    <tr>
        <td><%=stu.getId() %>
        </td>
        <td><%=stu.getName() %>
        </td>
        <td><%=stu.getPassword() %>
        </td>
        <td><%=stu.getSex() %>
        </td>
        <td><%=stu.getMajor() %>
        </td>
        <td><%=stu.getAge() %>
        </td>
        <td>
            <a href="/updatestu.jsp?id=<%=stu.getId()%>&name=<%=stu.getName()%>&age=<%=stu.getAge()%>">修改</a>
            <a href="DelateStudentServlet?id=<%=stu.getId()%>">删除</a>
        </td>
    </tr>
    <%}%>
    <%
        }
    %>
</table>
<hr/>
</body>
</html>
